<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>体育与健康课程管理系统</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/css/main.css"/>
      <link href="${pageContext.request.contextPath}/public/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/libs/modernizr.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/public/js/jquery-3.2.1.min.js"></script>
    <script src="${pageContext.request.contextPath}/public/js/layer/layer.js"></script>
</head>
<style type="text/css" media="screen">
.total{
    width:100%;
    height: 100%;
    background-color: #333;
    position: fixed;
    top:0px;
    opacity:0.5;
    margin:0px;
    z-index: 2;
    display:none;
}    
.add{
    width:400px;
    height:540px;
    background-color: #fff;
    position:fixed;
    top:50px;
    left:30%;
    border-radius: 5px;
z-index: 300;
display: none;
}
.add span
{
    float:right;
    font-size: 30px;
    margin-top: 10px;
    margin-right: 20px;
    color:#666;
    cursor: pointer;
}
.add span:hover
{
    color:#aaa;
}
.add p
{
    font-size: 18px;
    float:left;
    margin-top: 40px;
    margin-left:170px;
    color:#000;
    font-family: '微软雅黑';
    text-align: center;

}
.addtab
{
    float:left;
/*    margin-top:10px;*/
    margin-left: 50px;
}
.addtab tr
{
    float:left;
    margin-top: 20px;
    width:300px;
}
.addtab th
{
    width:90px;
    font-size: 15px;
    font-family: '微软雅黑';
    color:#000;
    float:left;
    font-weight:normal;
}
.addtab input
{
    border-radius: 5px;
    float:left;
    height:30px;
}
.btn12
{
    width:160px;
    height:40px;
    letter-spacing: 10px;
    font-size: 16px;
  
}
.require-red {
    color: #f60;
    font-family: serif;
    margin-right: 3px;
}
</style>
<body>
<div class="total">
</div>
<div class="add" id="add">
<span onclick="ad()">×</span>
<p>添加模板</p>
<form id="myform">
<table  class="addtab">
<tr><th><i class="require-red">*</i>考试时长（分钟）：</th><td><input  name='theoreticalPaperModelTime' type='text' onkeyup="value=value.replace(/[^\d.]/g,'')" placeholder="考试时长">分钟</td></tr>
<tr><th><i class="require-red">*</i>选择题数（个）：</th><td><input  name='theoreticalPaperModelChooseNumber' type='text'  placeholder="选择题数" onkeyup="value=value.replace(/[^\d.]/g,'')">个</td></tr>
<tr><th><i class="require-red">*</i>判断题数（个）：</th><td><input  name='theoreticalPaperModelJudgeNumber' type='text'  placeholder="判断题数" onkeyup="value=value.replace(/[^\d.]/g,'')">个</td></tr>
<tr><th><i class="require-red">*</i>单个选择题答题时间（秒）：</th><td><input  name='theoreticalPaperModelChooseTime' type='text'  placeholder="单个选择题答题时间" onkeyup="value=value.replace(/[^\d.]/g,'')">秒</td></tr>
<tr><th><i class="require-red">*</i>单个判断题答题时间（秒）：</th><td><input  name='theoreticalPaperModelJudgeTime' type='text'  placeholder="单个判断题答题时间" onkeyup="value=value.replace(/[^\d.]/g,'')">秒</td></tr>
</table>
<input class="btn btn-primary btn6 btn12 suba" name="sub" value="添加" type="button" style="margin-left:140px;margin-top:20px">
</form>

</div>
<p style="margin-top:15px;margin-left:40px; font-size:16px; border-left:3px #006dcc solid; padding-left:5px">查看所有试卷模板</p>
<div class="container clearfix" style="width:100%">
    <div class="main-wrap">
        <div class="search-wrap">
        </div>
        <div class="result-wrap" >
               <div class="result-title">
                    <div class="result-list">
                        <a href="javascript:;" onclick="ad()"><i class="icon-font"></i>新增试卷模板</a>
                    </div>
                </div>
                <div class="result-content" id="app" >
                    <table class="result-tab" width="100%" id="addto">
                        <tr>
                            <th>试卷ID</th>
                            <th>考试时长（分钟）</th>
                            <th>选择题数（个）</th>
                            <th>判断题数（个）</th>
                            <th>单个选择题答题时间（秒）</th>
                            <th>单个判断题答题时间（秒）</th>
                            <th>操作</th>
                        </tr>
                      <c:forEach items="${data}" var="v">
                        <tr >
                            <td>${v.theoreticalPaperModelId}</td>
                            <td><input style="height:30px" type="text" name="theoreticalPaperModelTime" value="${v.theoreticalPaperModelTime}" onkeyup="value=value.replace(/[^\d.]/g,'')" onchange="upd(${v.theoreticalPaperModelId},this.value,'theoreticalPaperModelTime')" >分钟</td>
                            <td><input style="height:30px" type="text" name="theoreticalPaperModelChooseNumber" value="${v.theoreticalPaperModelChooseNumber}" onkeyup="value=value.replace(/[^\d.]/g,'')" onchange="upd(${v.theoreticalPaperModelId},this.value,'theoreticalPaperModelChooseNumber')" >个</td>
                            <td><input style="height:30px" type="text" name="theoreticalPaperModelJudgeNumber" value="${v.theoreticalPaperModelJudgeNumber}" onkeyup="value=value.replace(/[^\d.]/g,'')" onchange="upd(${v.theoreticalPaperModelId},this.value,'theoreticalPaperModelJudgeNumber')" >个</td>
                           	<td><input style="height:30px" type="text" name="theoreticalPaperModelChooseTime" value="${v.theoreticalPaperModelChooseTime}" onkeyup="value=value.replace(/[^\d.]/g,'')" onchange="upd(${v.theoreticalPaperModelId},this.value,'theoreticalPaperModelChooseTime')" >秒</td>
                            <td><input style="height:30px" type="text" name="theoreticalPaperModelJudgeTime" value="${v.theoreticalPaperModelJudgeTime}" onkeyup="value=value.replace(/[^\d.]/g,'')" onchange="upd(${v.theoreticalPaperModelId},this.value,'theoreticalPaperModelJudgeTime')" >秒</td>
                            <td>
                            <button type="button" class="btn btn-danger" onclick="dele(${v.theoreticalPaperModelId})">删除</button>
                            </tr>
  					</c:forEach>
                    </table>
                    
                </div>
        </div>
    </div>
</div>

</body>
<script>
function ad()
{
    $('.total').toggle(500);
    $('#add').toggle(1000);

}

function dele(id)
{
	$.get("${pageContext.request.contextPath}/papermodel/deletepapermodel.action",{id:id},function(returndata){
		if(returndata.code==1)
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload(); 
              });
		else
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:1000}); 
	});
}
function upd(id,value,column)
{
	$.post("${pageContext.request.contextPath}/papermodel/updatepapermodel.action",{id:id,value:value,column:column},function(returndata){
		if(returndata.code==1)
			layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000});  
	});
}


$('.suba').click(function()
    {
    var theoreticalPaperModelTime=$('input[name=theoreticalPaperModelTime]');
	var theoreticalPaperModelChooseNumber=$('input[name=theoreticalPaperModelChooseNumber]');
	var theoreticalPaperModelJudgeNumber=$('input[name=theoreticalPaperModelJudgeNumber]');
	var theoreticalPaperModelChooseTime=$('input[name=theoreticalPaperModelChooseTime]');
	var theoreticalPaperModelJudgeTime=$('input[name=theoreticalPaperModelJudgeTime]');
	
    if(theoreticalPaperModelTime.val()=="")
    {
        layer.msg('考试时长不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        theoreticalPaperModelTime.focus();
        return ;
    }
    if(theoreticalPaperModelChooseNumber.val()=="")
    {
        layer.msg('选择题数不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        theoreticalPaperModelChooseNumber.focus();
        return ;
    }
    if(theoreticalPaperModelJudgeNumber.val()=="")
    {
        layer.msg('判断题数不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        theoreticalPaperModelJudgeNumber.focus();
        return ;
    }
    
    if(theoreticalPaperModelChooseTime.val()=="")
    {
        layer.msg('单个选择题答题时间不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        theoreticalPaperModelChooseTime.focus();
        return ;
    }
    
    if(theoreticalPaperModelJudgeTime.val()=="")
    {
        layer.msg('单个判断题答题时间不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
        theoreticalPaperModelJudgeTime.focus();
        return ;
    }

    var formData=$("#myform").serialize(); 
      $.ajax({
           url: "${pageContext.request.contextPath}/papermodel/addpapermodel.action",//提交地址
           type: 'POST',
           data: formData,
           async: false,
           cache: false,
           processData: false,
           success: function (returndata) {
            if(returndata.code==1){
              layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                location.reload(); 
              });
            }
            else
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});            
           },
           error: function (returndata) {
            layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});

       }
      });     

    });
</script>
</html>